const fs = require("fs-extra");
const path = require("path");

module.exports = async function writeFileTree(dir, files) {
  Object.keys(files).forEach((filename) => {
    const pathname = path.join(dir, filename);
    // path.dirname('/a/b/c.js) 返回 '/a/b' 用于提取目录名称的文件路径
    fs.ensureDirSync(path.dirname(pathname));
    //  ensureDir 创建目录  确保目录的存在。如果目录结构不存在,就创建一个。
    fs.writeFileSync(pathname, files[filename]);
  });
};
